package com.datastax.driver.mapping;

import com.google.common.util.concurrent.ListenableFuture;

import java.util.List;

/**
 * Created by dave on 18-7-26 下午12:43.
 */
public interface BaseDao<T> {

    CassandraMapper<T> getMapper();

    default void save(T entity) {
        getMapper().save(entity);
    }

    default void save(List<T> entities) {
        getMapper().save(entities);
    }

    default ListenableFuture<Void> saveAsync(T entity) {
        return getMapper().saveAsync(entity);
    }

    default ListenableFuture<Void> saveAsync(List<T> list) {
        return getMapper().saveAsync(list);
    }

    default void delete(T entity) {
        getMapper().delete(entity);
    }

    default void delete(T entity, Mapper.Option... options) {
        getMapper().delete(entity, options);
    }

    default ListenableFuture<Void> deleteAsync(T entity) {
        return getMapper().deleteAsync(entity);
    }

    default ListenableFuture<Void> deleteAsync(T entity, Mapper.Option... options) {
        return getMapper().deleteAsync(entity, options);
    }

    /**
     * 获取单条记录
     * @param objects 按照主键顺序的参数列表
     * @return
     */
    default T get(Object... objects) {
        return getMapper().get(objects);
    }

    /**
     * 获取单条记录
     * @param objects 按照主键顺序的参数列表
     * @return
     */
    default ListenableFuture<T> getAsync(final Object... objects) {
        return getMapper().getAsync(objects);
    }
}
